<template>
  <section>
    <div class="container">
      <div class="handle-box">
        <el-input
          v-model="real_name"
          placeholder="用户"
          clearable
          class="handle-input mr10"
          @keyup.enter.native="handleSearch"
        ></el-input>
        <el-input
          v-model="mobile"
          placeholder="手机号"
          clearable
          class="handle-input w200 mr10"
          @keyup.enter.native="handleSearch"
        ></el-input>
        <el-select
          v-model="level"
          placeholder="筛选用户等级"
          clearable
          @keyup.enter.native="handleSearch"
          class="mr10"
        >
          <el-option label="全部" value=""></el-option>
          <el-option
            v-for="item in levelOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
        <el-button type="primary" icon="search" @click="handleSearch"
          >搜索</el-button
        >
        <el-button type="danger" @click="handleReset">清空</el-button>
      </div>
      <el-table
        :data="tableData"
        border
        class="table"
        ref="multipleTable"
        v-loading="loading"
      >
        <el-table-column prop="id" label="ID"></el-table-column>
        <el-table-column label="姓名">
          <template slot-scope="scope">
            <span v-if="scope.row.real_name_status == 1">{{
              scope.row.real_name
            }}</span>
            <span style="color:#f00" v-if="scope.row.real_name_status == 0"
              >未实名</span
            >
          </template>
        </el-table-column>
        <el-table-column prop="mobile" label="电话"></el-table-column>
        <el-table-column label="等级">
          <template slot-scope="scope">
            <span>{{ scope.row.level_text }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="cash" label="账户余额"></el-table-column>
        <el-table-column prop="create_time" label="注册时间"></el-table-column>
        <el-table-column prop="recommend_user_real_name" label="推广人">
          <template slot-scope="scope">
            <span v-if="scope.row.recommend_user_mobile"
              >{{ scope.row.recommend_user_real_name }}({{
                scope.row.recommend_user_mobile
              }})</span
            >
            <span v-if="!scope.row.recommend_user_mobile">没有推广人</span>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination" style="text-align:center">
        <el-pagination
          background
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange"
          layout="sizes, prev, pager, next,total"
          :total="pagination.total"
          :current-page.sync="pagination.currentPage"
          :page-size="pagination.pageSize"
          :page-sizes="pagination.pageSizes"
          :hide-on-single-page="true"
        >
        </el-pagination>
      </div>
    </div>
  </section>
</template>

<script>
import { userList } from '@/api/modules/branch'
import moment from 'moment'

export default {
  name: 'branchUser',
  components: {},
  data() {
    return {
      loading: true,
      tableData: [],
      real_name: '',
      mobile: '',
      card_number: '',
      level: '',
      pagination: {
        total: 0,
        pageSize: 20,
        currentPage: 1,
        pageSizes: [10, 20, 30]
      },
      gridData: [],
      levelOptions: []
    }
  },
  computed: {},
  created() {
    this.getData()
  },
  methods: {
    search() {
      this.getData()
    },
    // 分页导航
    handleCurrentChange(val) {
      this.pagination.currentPage = val
      this.getData()
    },
    handleSizeChange(val) {
      this.pagination.pageSize = val
      this.getData()
    },
    // 获取数据
    getData() {
      this.loading = true
      userList({
        page: this.pagination.currentPage,
        pageSize: this.pagination.pageSize,
        mobile: this.mobile,
        real_name: this.real_name,
        card_number: this.card_number,
        level: this.level
      }).then(res => {
        this.loading = false
        this.tableData = res.data.list
        this.levelOptions = res.data.level
        this.pagination.total = res.data.pagination.total
      })
    },

    /**
     * 重置
     */
    handleReset() {
      this.page = 1
      this.pageSize = 20
      this.mobile = ''
      this.real_name = ''
      this.card_number = ''
      this.level = ''
      this.getData()
    },

    handleFatherReset() {
      this.father_mobile = ''
      this.father_real_name = ''
      this.handleFatherSearch()
    },

    /**
     * 搜索
     */
    handleSearch() {
      // this.$router.replace({ query: '' })
      this.getData()
    }
  }
}
</script>

<style lang="scss" scoped>
.handle-box {
  margin-bottom: 20px;
}

.handle-select {
  width: 120px;
}

.handle-input {
  width: 100px;
  display: inline-block;
}
.w200 {
  width: 200px;
}

.del-dialog-cnt {
  font-size: 16px;
  text-align: center;
}
.table {
  width: 100%;
  font-size: 14px;
}
.red {
  color: #ff0000;
}
.mr10 {
  margin-right: 10px;
}
</style>
